﻿// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. 
// See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace System.Threading.Actors
{
    public interface IActorPromise
    {
        string Result { get; } // Blocks waiting for result
        T GetTypedResult<T>(); // Allows conversion from JSON string to T

        // Allows for continuation-based handling of the result.
        // This promise will be passed as the first argument to the continuation handler
        // If you specify a parameters array of length n, that will be the second through n + 1'th parameter.
        // Note: If you want to wait for the continuation to complete, you must block on the IActorPromise returned by
        // ContinueWith, not this IActorPromise.  The Wait and Result and GetTypedResult methods on this instance will 
        // NOT block until the continuation is done.  
        // For example:
        //   IActorPromise proxyPromise = state.GetActorProxyAsync(...);
        //   IActorPromise continuationPromise = proxyPromise.ContinueWith("MyContinuation", ...);
        //   proxyPromise.Wait();  // Continuation may not have completed, but getting this proxy will have.
        //   continuationPromise.Wait();  // Continuation will have finished.
        IActorPromise ContinueWith(string methodName, params Object[] parameters);

        // Wait is primarily useful for testing.  Most real programs would call Result, but our tests are more exacting.
        void Wait();
        bool Wait(int timeoutMilliseconds);

        // Properties associated with exception handling
        bool IsFaulted { get; } // Allows continuation to check whether or not the operation faulted
        string ExceptionType { get; }
        string ExceptionMessage { get; }
        string ExceptionStackTrace { get; }
    }
}
